package api.ttfeed;

import android.content.Context;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;

import java.lang.ref.SoftReference;

/**
 * 个性化模板信息流广告，
 * 开发者不用自行对广告样式进行编辑和渲染，可直接调用相关接口获取广告view,广告样式模板以及微调后期支持开发者编辑
 * 2.5.xx版本后申请的KEY 后台强制要用渲染模版
 */
public abstract class PreloadExpress_API_TT {

    public static String clazz = "com.dotools.toutiaolibrary.TT_PreloadExpress";

    private static SoftReference<PreloadExpress_API_TT> sf;

    public synchronized static PreloadExpress_API_TT getInstance() {

        if (sf == null || sf.get() == null) {
            Object o = null;
            try {
                o = Class.forName(clazz).newInstance();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (o != null) {
                sf = new SoftReference<>((PreloadExpress_API_TT) o);
                return (PreloadExpress_API_TT) o;
            }
        }
        return sf == null ? null : sf.get();
    }

    public abstract void LoadTTExpress(Context context, String appid, String adposid,
                                       int expressViewWidth, int expressViewHeight, int count,int downloadMode,
                                       boolean isDebug,
                                       final TTExpressLoadListener listener);


    public abstract void expressDestroy();
    public abstract void showExpress(ViewGroup container,TTExpressInteractionListener listener);


    /**
     * 点击X绑定关闭广告事件
     */
    public abstract void bindDislike(FragmentActivity activity,ViewGroup container);


    public interface TTExpressLoadListener {
        void onLoad(int size);
        void onError(int code, String message);
    }

    public interface TTExpressInteractionListener {
        void onObClicked(int type);
        void onObShow(int type);
        void onRenderSuccess();
        void onError(int code, String message);
    }
}